import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Saw here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Saw extends Trap
{
    private int distance;
    private boolean goingBack;
    private int movement;
    private Timer aniTimer=new Timer();

    
    public Saw(int x,int del,int iniD,int d)
    {
        super(x,del,iniD);
        
        distance=d;
        movement=0;
        damage=20;
        goingBack=true;
        
        setImage(new GreenfootImage("saw.png"));
        
    }
    
    public void act() 
    {
        timer.tick();
        activeTimer.tick();
        aniTimer.tick();
        
        GameWorld world=(GameWorld)getWorld();
        setLocation(world.getScrollx()+360+posX+movement,getY());
        
        if(active==true || !activeTimer.wait(initialDelay))     
        activeImage();
        if(active==false)
        return;
        
        if(!aniTimer.wait(50))
        turn(45);
        
        
        if(goingBack==true)
        {
            if(posX+movement>posX+distance)
            {
                if(!timer.wait(delay))
                goingBack=false;
            }else
            movement++;
        }
        else
        {
            if(posX+movement<posX-distance)
            {
                if(!timer.wait(delay))
                goingBack=true;
            }else
            movement--;
        }
        
        Player player=getPlayer();
        
        if(isTouchingPlayer())
        player.getHurt(damage);
    }    
}
